package flyweight;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 使用工厂模式来创建享元对象（TreeType）
 */
public class TreeTypeFactory {
    private Map<String, TreeType> flyweights = new HashMap<>();

    public TreeType getTreeType(String type, String color, String texture) {
        String key = String.valueOf(UUID.randomUUID()); // UUID 生成唯一标识

        if (!flyweights.containsKey(key)) {
            flyweights.put(key, new TreeType(type, color, texture));
        }

        return flyweights.get(key);
    }
}
